package com.sesame.user.controller;

import com.sesame.user.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import kim.sesame.common.result.ApiResult;
import kim.sesame.common.web.controller.AbstractWebController;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


@Api(description = "用户接口")
@CommonsLog
@RestController
@RequestMapping("/user")
public class UserController extends AbstractWebController {

    @ApiOperation(value = "获取用户列表", notes = "xxxxxxxxxxxxxxxx")
    @GetMapping("/list")
    public ApiResult list() {

        List<User> list = Arrays.asList(
                new User("张三")
                , new User("李四")
        );
        return success(list);
    }

    @ApiOperation(value = "创建用户", notes = "根据User对象创建用户")
    @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    @PostMapping("/postUser")
    public ApiResult postUser(@RequestBody User user) {

        return success(user);
    }

    @ApiOperation(value = "获取用户详细信息", notes = "根据url的id来获取用户详细信息")
    @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long")
    @PostMapping("/deleteUser/{id}")
    public ApiResult getUser(@PathVariable Long id) {
        return success(new User(id + ""));
    }

    @ApiOperation(value = "更新用户详细信息", notes = "根据url的id来指定更新对象，并根据传过来的user信息来更新用户详细信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Long"),
            @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    })
    @PostMapping("/putUser/{id}")
    public ApiResult putUser(@PathVariable Long id, @RequestBody User user) {
        return success();
    }

    @ApiOperation(value = "测试json接收", notes = "111111111111111111")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
    })
    @PostMapping("/testObj")
    public ApiResult testObj( @RequestBody User user) {
        return success(user);
    }
    @ApiOperation(value = "测试jsonArr接收", notes = "22222")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "list", value = "用户实体user集合", required = true, dataType = "List")
    })
    @PostMapping("/testArr")
    public ApiResult testArr( @RequestBody List<User> list) {
        return success(list);
    }


}
